<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script>

// Check that the number of ICE candidates that we can generate hasn't regressed
// At the moment (Nov 2017), the limit is approx
// - 3900 on Linux

let peerConnections = [];

function allocatePeerConnection(candidates) {
  peerConnections.push(new RTCPeerConnection(
      {iceCandidatePoolSize: candidates}));
}

function cleanUpPeerConnections() {
  // Close all peer connections so that they may be garbage collected.
  peerConnections.forEach(pc => {
    pc.close();
  });
  peerConnections = [];
}

promise_test(function(t) {
  return new Promise(function(resolve, reject) {
    // We're aiming to create > 3000 candidates with minimum effort.
    for (let i = 0; i < 13; i++) {
      allocatePeerConnection(250);
    }
    t.step_timeout(function() {
      cleanUpPeerConnections();
      resolve()
    }, 2000);
  });
}, 'Create many PeerConnections with large pool sizes', {timeout: 60000});

</script>
</body>
</html>
